<?php
class Career_selection_model extends CI_Model {

    function categorylist(){
        $this->load->database();
        $query = $this->db->query("SELECT distinct career_category FROM career");
        return $query->result();
    }

    function filtercar(){
        $this->load->database();
        $query = $this->db->query("SELECT * FROM career where riasec_code = 'ECS' ");
        return $query->result();
    }

//searches
    function searchkey($keyword, $cate)
    {
        $this->load->database();
        $keyword = $this->input->post('keyword');
        $cate = $this->input->post('cate');
        $query = $this->db->query("SELECT * FROM career c where $cate LIKE '%$keyword%'");
        return $query->result();
    }

    function searchcate($cate){
        $this->load->database();
        $cate = $this->input->post('cate');
        $query = $this->db->query("SELECT * FROM career c where career_category LIKE '%$cate%'");
        return $query->result();
    }

    function searchpersonality(){
        $this->load->database();
        $type1 = $this->input->post('type1');
        $type2 = $this->input->post('type2');
        $type3 = $this->input->post('type3');
        $riasec = $type1.$type2.$type3;
        $query = $this->db->query("SELECT * FROM career c where riasec_code LIKE '%$riasec%'");
        return $query->result();

    }

    function careerper($cate, $keyword){
        $this->load->database();
        $keyword = $this->input->post('keyword');
        $cate = $this->input->post('cate');
        $query = $this->db->query("SELECT * FROM career where riasec_code = 'ECS' AND $cate LIKE '%$keyword%'");
        return $query->result();
    }



//viewing own career and deletion

    function entry_delete($user_id) {
        $id = $this->input->post('career_id');
        if (count($id) == 1) {
            $query = $this->db->query("DELETE FROM student_has_career WHERE student_id = " .$user_id." AND career_id=".$id[0]);
         }else {
            foreach ($id as $ids) {
                $query = $this->db->query("DELETE FROM student_has_career WHERE student_id = " . $user_id." AND career_id=".$ids);
             }
        }
        return $query;
    }

    function mycareer($user_id){
        $this->load->database();
        $query = $this->db->query("Select * FROM student_has_career shc, career c WHERE shc.student_id = " .$user_id." AND (shc.career_id = c.career_id)");
        return $query->result();
    }





//selections
    function selCareerModel() {
        $ids = $this->input->post('career_id');
        $sql1 = array();
        foreach ($ids as $id) {
            $query = $this->db->query("SELECT * FROM career WHERE career_id =$id");
            $query = $query->result();
            foreach ($query as $sql) {
                $query1 = array($sql->career_name, $sql->career_id);
                array_unshift($sql1, $query1);
            }
        }
        return $sql1;
//        }
    }

    function confirmSelectionModel($id,$user_id) {
        $sql = $this->db->query("SELECT * FROM student_has_career WHERE career_id =$id AND student_id =" . $user_id."");
        if (count($sql->result()) == 0) {
            $query = $this->db->query("INSERT INTO student_has_career(career_id,student_id) VALUES($id,'" . $user_id . "')");
            return $query;
        }
    }

}
?>
